
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>限流--分布式限流 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="上一篇《限流--单机限流》讲述了单机限流的原理和技术实现，那么在现在分布式">
<meta name="keywords" content="限流">
<meta property="og:type" content="article">
<meta property="og:title" content="限流--分布式限流">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2018/09/09/限流-分布式限流/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="上一篇《限流--单机限流》讲述了单机限流的原理和技术实现，那么在现在分布式">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/09/限流-分布式限流/d1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/09/限流-分布式限流/d2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/09/限流-分布式限流/d3.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/09/限流-分布式限流/d4.png">
<meta property="og:updated_time" content="2018-09-09T07:44:49.691Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="限流--分布式限流">
<meta name="twitter:description" content="上一篇《限流--单机限流》讲述了单机限流的原理和技术实现，那么在现在分布式">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/09/09/限流-分布式限流/d1.png">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2018/09/09/限流-分布式限流/" title="限流--分布式限流" itemprop="url">限流--分布式限流</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2018-09-09T04:34:00.000Z" itemprop="datePublished"> Published 2018-09-09</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#基于redis实现接口限流"><span class="toc-number">1.</span> <span class="toc-text">基于redis实现接口限流</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">2.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<pre><code>上一篇《限流--单机限流》讲述了单机限流的原理和技术实现，那么在现在分布式
</code></pre><a id="more"></a>
<pre><code>架构盛行的互联网时代，对于资源紧俏或者出于安全防范的目的，对一些核心的接口会做
限流，或者对于一些黑灰产业在应用入口处做拦截或者限流。先举两个例子让大家更有体感：
</code></pre><p><strong>案例一:数据资源紧缺</strong><br>        对于互联网应用，数据库很多时候会变成稀缺资源，很多小公司架构模式是在应用层实现<br>    分布式架构，但是数据库层可能是单点或者简单的主从结构：<br><img src="/typhoon/2018/09/09/限流-分布式限流/d1.png" alt="ratelimiter" title="ratelimiter"></p>
<pre><code>    在流量高峰期QPS可能会超过DB能够支撑的阈值，如果不做管控或限制，可能会因为DB挂掉
导致整个应用挂掉，正常访问那部分流量也会受到影响，这个时候我们会考虑在一些热点接口做
限流管控，对于上述的架构模式，一般是在应用或者访问层限流，对应就是http接口和rpc接口，
具体在哪一层限流，需要根据具体的业务场景做区分，应用层更关注具体业务场景，服务层更多
关注的是业务场景的代码实现，更通用。两种方式各有优劣，应用层也就是我们所说的控制器层
，按照分层设计思想来说这一层不做逻辑的，如果加了限流其实就违背了这个思想，但是从业务
角度思考，加在这一层其实是以更细的业务粒度做流量管控；加在服务层，更加通用也服务分层
设计思想，但是如果服务层暴露给上层应用的是一个通用的接口，那么此处限流粒度就有点粗，
可能原本想对某一个业务场景限流，但是实际上影响了n个业务场景的访问。
</code></pre><p><strong>案例二:防黑灰产和爬虫</strong><br>        就目前来说，国内的电商可以说已经发展到了鼎盛时期，现在也产生了不计其数的个人或者注册<br>    公司的团队依附于大的电商平台来生存，他们的手段就是以用户的身份去访问电商平台，然后对拿到<br>    的数据做比较专业的分析，然后把一些优惠信息卖给其他人来牟利。<br>        那么对于电商平台来说，其实这部分流量对我来说就是非法流量，那如果我能够通过大数据或者<br>    其他方式甄别出来这部分流量，并且加入黑名单，对其访问做限制，对于电商平台来说首先是一种<br>    自我保护措施，再者其实就是把优惠分配给平台上真正的优质用户。<br>        基于这个场景，我此处暂时列出一种解决方案：<br><img src="/typhoon/2018/09/09/限流-分布式限流/d2.png" alt="ratelimiter" title="ratelimiter"></p>
<pre><code>    在反向代理层(请求尚未进入真实服务器)对在黑名单中的用户做限流，限制其访问频次，如果是
黑灰产或者爬虫，其肯定会频繁的访问，在nginx层限制在黑名单中的用户每秒只能访问一次，从一定
程度上就能起到系统保护作用。

    上边两个案例描述了分布式应用中需要限流的一些点，还有不同场景下限流的时机。对于案例一，
目前可是基于redis实现接口限流，对于案例二，可以使用lua+redis实现在代理层限流。
此篇接下来将重点讲述案例一中的基于redis实现接口访问限流的原理及技术实现，案例
二中的nginx+lua+redis实现限流后续篇幅中会讲述。
</code></pre><h5 id="基于redis实现接口限流"><a href="#基于redis实现接口限流" class="headerlink" title="基于redis实现接口限流"></a>基于redis实现接口限流</h5><pre><code>    redis2.6版本增加了对lua脚本的原生支持，为了保证限流操作中redis每个步骤的原子性，我们此处
借助lua脚本操作redis，核心代码如下：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> <span class="keyword">static</span> JedisPool jedisPool = SpringContextUtil.getBean(<span class="string">"jedisPool"</span>,JedisPool.class);</div><div class="line"></div><div class="line">   <span class="comment">/**</span></div><div class="line">    * 针对资源key,每seconds秒最多访问maxCount次,超过maxCount次返回false</div><div class="line">    *</div><div class="line">    * <span class="doctag">@param</span> key</div><div class="line">    * <span class="doctag">@param</span> seconds</div><div class="line">    * <span class="doctag">@param</span> limitCount</div><div class="line">    * <span class="doctag">@return</span></div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span>  <span class="keyword">boolean</span> <span class="title">tryAccess</span><span class="params">(String key, <span class="keyword">int</span> seconds, <span class="keyword">int</span> limitCount)</span> </span>&#123;</div><div class="line">       LimitRule limitRule = <span class="keyword">new</span> LimitRule();</div><div class="line">       limitRule.setLimitCount(limitCount);</div><div class="line">       limitRule.setSeconds(seconds);</div><div class="line">       <span class="keyword">return</span> tryAccess(key, limitRule);</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   <span class="comment">/**</span></div><div class="line">    * 针对资源key,每limitRule.seconds秒最多访问limitRule.limitCount,超过limitCount次返回false 超过lockCount</div><div class="line">    * 锁定lockTime</div><div class="line">    * </div><div class="line">    * <span class="doctag">@param</span> key</div><div class="line">    * <span class="doctag">@param</span> limitRule</div><div class="line">    * <span class="doctag">@return</span></div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">tryAccess</span><span class="params">(String key, LimitRule limitRule)</span> </span>&#123;</div><div class="line"></div><div class="line">       Jedis jedis = <span class="keyword">null</span>;</div><div class="line">       <span class="keyword">long</span> count = -<span class="number">1</span>;</div><div class="line">       <span class="keyword">try</span> &#123;</div><div class="line">           jedis = jedisPool.getResource();</div><div class="line">           List&lt;String&gt; keys = <span class="keyword">new</span> ArrayList&lt;String&gt;();</div><div class="line">           String newKey = <span class="string">"limit:"</span> + key + <span class="string">":"</span> + limitRule.getSeconds();</div><div class="line">           keys.add(newKey);</div><div class="line">           List&lt;String&gt; args = <span class="keyword">new</span> ArrayList&lt;String&gt;();</div><div class="line">           args.add(Math.max(limitRule.getLimitCount(), limitRule.getLockCount()) + <span class="string">""</span>);</div><div class="line">           args.add(limitRule.getSeconds() + <span class="string">""</span>);</div><div class="line">           args.add(limitRule.getLockCount() + <span class="string">""</span>);</div><div class="line">           args.add(limitRule.getLockTime() + <span class="string">""</span>);</div><div class="line"></div><div class="line">           count = Long.parseLong(jedis.eval(buildLuaScript(limitRule), keys, args) + <span class="string">""</span>);</div><div class="line">           <span class="keyword">return</span> count &lt;= limitRule.getLimitCount();</div><div class="line">       &#125; <span class="keyword">finally</span> &#123;</div><div class="line">           <span class="keyword">if</span> (jedis != <span class="keyword">null</span>)</div><div class="line">               jedis.close();</div><div class="line">       &#125;</div><div class="line">   &#125;</div><div class="line">   <span class="comment">/**</span></div><div class="line">    * 创建lua脚本交给redis执行</div><div class="line">    * &lt;p&gt;新版本redis支持lua脚本&lt;/p&gt;</div><div class="line">    * &lt;p&gt;lua脚本被执行的时候能够保证原子性&lt;/p&gt;</div><div class="line">    * <span class="doctag">@param</span> limitRule</div><div class="line">    * <span class="doctag">@return</span></div><div class="line">    */</div><div class="line">   <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">buildLuaScript</span><span class="params">(LimitRule limitRule)</span> </span>&#123;</div><div class="line">       StringBuilder lua = <span class="keyword">new</span> StringBuilder();</div><div class="line">       lua.append(<span class="string">"\nlocal c"</span>);</div><div class="line">       lua.append(<span class="string">"\nc = redis.call('get',KEYS[1])"</span>);<span class="comment">//KEYS[1]表示要限制访问的key</span></div><div class="line">       lua.append(<span class="string">"\nif c and tonumber(c) &gt; tonumber(ARGV[1]) then"</span>);<span class="comment">//ARGV[1]=限制访问的次数</span></div><div class="line">       lua.append(<span class="string">"\nreturn c;"</span>);</div><div class="line">       lua.append(<span class="string">"\nend"</span>);</div><div class="line">       lua.append(<span class="string">"\nc = redis.call('incr',KEYS[1])"</span>);</div><div class="line">       lua.append(<span class="string">"\nif tonumber(c) == 1 then"</span>);</div><div class="line">       lua.append(<span class="string">"\nredis.call('expire',KEYS[1],ARGV[2])"</span>);<span class="comment">//如果是限流期间key第一次访问，重新设置ARGV[2]失效时间</span></div><div class="line">       lua.append(<span class="string">"\nend"</span>);</div><div class="line">       <span class="keyword">if</span> (limitRule.enableLimitLock()) &#123;<span class="comment">//如果设置了超过限流次数锁定</span></div><div class="line">           lua.append(<span class="string">"\nif tonumber(c) &gt; tonumber(ARGV[3]) then"</span>);<span class="comment">//ARGV[3]访问锁定次数</span></div><div class="line">           lua.append(<span class="string">"\nredis.call('expire',KEYS[1],ARGV[4])"</span>);<span class="comment">//ARGV[4]访问锁定时间</span></div><div class="line">           lua.append(<span class="string">"\nend"</span>);</div><div class="line">       &#125;</div><div class="line">       lua.append(<span class="string">"\nreturn c;"</span>);</div><div class="line">       <span class="keyword">return</span> lua.toString();</div><div class="line">   &#125;</div></pre></td></tr></table></figure>
<pre><code>上述代码中和新逻辑是tryAccess方法：
</code></pre><img src="/typhoon/2018/09/09/限流-分布式限流/d3.png" alt="ratelimiter" title="ratelimiter">
<pre><code>    首先获取redis连接，然后用冒号隔开构建redis存储的key，接着构建了两个列表，一个是key，一个是参数，再然后
调用jedis客户端的eval方法使用原生的lua脚本执行命令，如果返回值小于限流大小就允许访问，否则拒绝。
    编写测试代码：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">	AbstractApplicationContext context = <span class="keyword">new</span> ClassPathXmlApplicationContext(<span class="string">"spring-root.xml"</span>);</div><div class="line">	context.start();</div><div class="line"></div><div class="line">	String ipHost = <span class="string">"192.168.1.1"</span>;</div><div class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span> ;i &lt; <span class="number">10</span>; i ++) &#123;</div><div class="line">		<span class="keyword">boolean</span> result = RateLimiter.tryAccess(ipHost,<span class="number">1</span>,<span class="number">1</span>);</div><div class="line">		<span class="keyword">if</span>(result) &#123;</div><div class="line">			System.out.println(<span class="string">"访问成功"</span>);</div><div class="line">		&#125; <span class="keyword">else</span> &#123;</div><div class="line">			System.out.println(<span class="string">"访问受限"</span>);</div><div class="line">		&#125;</div><div class="line">	&#125;</div><div class="line">	context.stop();</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>运行测试代码，结果如下：
</code></pre><img src="/typhoon/2018/09/09/限流-分布式限流/d4.png" alt="ratelimiter" title="ratelimiter">
<pre><code>    我们设置的访问限制是每秒允许一次，然后循环调用10次，看后只有一次成功了，也就是成功限流了超过阈值的部分，
虽然这里是单机运行，对于多台服务器发起的请求同样能够限制，因为所有服务器走到限流逻辑的时候都会去redis获取访问
资格。至于多服务器发起的请求限流，这里就不做赘述，感兴趣可以自己模拟实现。
</code></pre><h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><pre><code>    通过上述一系列描述，想必对分布式限流有了比较深刻的认识，使用Redis+lua脚本编码实现限流，首先实现了限流逻辑中
对redis查询和更新操作的原子性，然后从效果层面看，也实现了对访问频率的限制。其实接口粒度的限流有很多时候并不能解
决所有问题，首先既然能够走到接口限流，那么请求必然已经进入了服务器，就算在接口层面被拦截，但也势必占用一定的系统
资源，对于限流有句话讲的特别好“限流越早越好”，也就是说能够在服务器外层拦截或者限制掉最好，很多应用架构都是在nginx
层做请求拦截和限流。希望此篇赘述对大家对限流的理解有所启发，在日常开发中有所帮助。
</code></pre>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/架构/">架构</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/限流/">限流</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2018/09/09/限流-分布式限流/" data-title="限流--分布式限流 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/09/14/设计模式-责任链模式详解/" title="设计模式----责任链模式详解">
  <strong>上一篇：</strong><br/>
  <span>
  设计模式----责任链模式详解</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2018/09/08/限流-单机限流/"  title="限流--单机限流">
 <strong>下一篇：</strong><br/> 
 <span>限流--单机限流
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#基于redis实现接口限流"><span class="toc-number">1.</span> <span class="toc-text">基于redis实现接口限流</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">2.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
